home *** CD-ROM | disk | FTP | other *** search
- /* putw.c, from p. 456 of Turbo C Bible */
- #include <stdio.h>
- /* The string "Hi There\n" in hexa- */
- /* decimal. Because of byte-ordering */
- /* conventions they may not look */
- /* obvious. By the way, here are the */
- /* ASCII codes : */
- /* H = 48, i = 69, blank = 20, T = 54, */
- /* h = 68, e = 65, and r = 72 */
- int words[] = {0x6948, 0x5420, 0x6568, 0x6572, 0x0A0D};
- int numw = sizeof(words)/sizeof(int);
- main()
- {
- int i;
- FILE *infile;
- char filename[81];
- printf("Enter name of a file to write to: ");
- gets(filename);
- /* Open the file for reading */
- if ((infile = fopen(filename, "wb")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- /* Write the words to the file */
- for (i = 0; i < numw; i++)
- {
- if (putw(words[i], infile) == EOF)
- {
- /* Check if there was a real error */
- if (ferror(infile) != 0)
- {
- printf("File: %s write error\n", filename);
- exit(0);
- }
- }
- }
- /* Ask user to type file out and check */
- printf("To see results use 'TYPE %s'\n", filename);
- }